import java.util.HashSet;

public class LQB_code1_9 {
    public static void main(String[] args) {
        int x = 1;
        while (true){
            int x2 = x*x;
            int x3 = x*x*x;
            String s1 = x2 +"";
            String s2 = x3 +"";
            String s3 = s1+s2;
            if (s3.length()!=10){
                x++;
                continue;
            }
            char[] c = s3.toCharArray();
            HashSet<Character> set = new HashSet<Character>();
            for (char ch:c){
                set.add(ch);
            }
            if (set.size()==10){
                break;
            }
            x++;
        }
        System.out.print(x);
    }
}
